package com.chenailin.www.daoimpl;

import com.chenailin.www.dao.ReportDAO;
import com.chenailin.www.pojo.Report;
import com.chenailin.www.util.DBUtil;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class ReportDAOImpl implements ReportDAO {
    // 添加报表
    @Override
    public boolean addReportRecord(Report report) throws SQLException {
        String sql = "INSERT INTO reports (date, file_path) VALUES (?, ?)";
        try (Connection conn = DBUtil.getConnection();
             PreparedStatement ps = conn.prepareStatement(sql)) {
            ps.setDate(1, Date.valueOf(report.getReportDate()));
            System.out.println(report.getFilePath());
            ps.setString(2, report.getFilePath());
            //受影响的行数
            int affectedRows = ps.executeUpdate();
            return affectedRows > 0;
        } catch (SQLException e) {
            System.err.println("数据库操作失败: " + e.getMessage());
            return false;
        }
    }
}
